<?php
/**
 * 修改密码
 */
//输入的密码
$change_password_pwd_input=!empty($_POST['password'])?trim($_POST['password']):"";
//确认密码
$change_password_pwd_confirm_input=!empty($_POST['password_confirm'])?trim($_POST['password_confirm']):"";
//原密码
$change_password_former=!empty($_POST['password_former'])?trim($_POST['password_former']):"";
//验证码
$change_password_icode=!empty($_POST['captcha'])?trim($_POST['captcha']):"";
//加密新密码
$change_password_pwd=md5($change_password_pwd_confirm_input.$pwdconstant);
//加密原密码
$change_password_pwd_former=md5($change_password_former.$pwdconstant);
if(empty($userInfo['uid'])){
	$fun->msg("您还没有登录,无法修改密码",$list_url['login'],2,$title="修改密码提示",$back_color="f78a12");
}else{
	//||(empty($change_password_former))
	if((empty($change_password_pwd_input))||($change_password_pwd_confirm_input=="")||($change_password_icode == "")){
		$fun->msg("请您认真填写修改信息",$list_url['change_password'],2,$title="修改密码提示",$back_color="f78a12");
	}else{
	
		if($change_password_pwd_input<>$change_password_pwd_confirm_input){
			$fun->msg("您两次输入的密码不一致",$list_url['change_password'],2,$title="修改密码提示",$back_color="f78a12");
		}elseif(strcasecmp($change_password_icode,@$_SESSION['randcode'])<>0){
			$fun->msg("您输入的验证码错误",$list_url['change_password'],2,$title="修改密码提示",$back_color="f78a12");
		}else{
			//AND `password`='{$change_password_pwd_former}'
			$check_user=$db->get_one("SELECT `uid`, `status`, `uname`,`logintime`,`login_num`,`status` FROM `".$tbprefix."user` WHERE  `uid`='".$userInfo['uid']."' AND `is_valid`='1' AND 1");
	
			if($check_user['uid']){
				if($check_user['status']==1){
					/**
					 * 成功修改密码，更新修改密码时间与登录次数
					 */
					$dataArray['password']=$change_password_pwd;
					//修改密码时间
					$dataArray['addtime']=$m_now_time;
					//修改密码IP
					$dataArray['modify_ip']=$fun->get_web_ip();
					if($db->update("`".$tbprefix."user`",$dataArray,$condition="uid='".$check_user['uid']."' AND 1"))
					{
						$insert_uid=$db->insert_id();
						//存储登录的基本信息
						//@$_SESSION['web_user_uid']=$fun->authcode($check_user['uid'],'ENCODE', $pwdconstant,$expiry=0);
						unset($_SESSION['web_user_uid']);//清除登录的用户id
						
						
						//修改shopnc 密码
						//shopNc db class
						$dbshopnc = new DB($db_config["hostname"], $db_config["username"], $db_config["password"], $db_config["database_shop"], $db_config);
						$datashop["member_passwd"] = md5($change_password_pwd_confirm_input);
						$shop_uprs = $dbshopnc->update("shopnc_member",$datashop,"member_name='".$check_user['uname']."' AND 1");
						
						//修改discuz密码
						//discuz db class
						$dbdiscuz = new DB($db_config["hostname"], $db_config["username"], $db_config["password"], $db_config["database_dz"], $db_config);
						$discuz_user = $dbdiscuz->get_one("SELECT `salt` FROM `pre_ucenter_members` WHERE `username`='{$check_user['uname']}' AND 1");
						$datadiscuz["password"] = md5(md5($change_password_pwd_confirm_input).$discuz_user["salt"]);
						$discuz_uprs = $dbdiscuz->update("pre_ucenter_members",$datadiscuz,"username='".$check_user['uname']."' AND 1");
						
						//同步退出
						/* SHOPNC loginout */
						$shopncloginout = SHOPNC_DOMAIN."index.php?act=login&op=logout";
						echo '<iframe height=0 width=0 style="display:none;" src="'.$shopncloginout.'"></iframe>';
						/* SHOPNC loginout */
						
						
						/* discuz loginout */
						$discuzloginout = DISCUZ_DOMAIN."member.php?mod=logging&action=logout";
						echo '<iframe height=0 width=0 style="display:none;" src="'.$discuzloginout.'"></iframe>';
						/* discuz loginout */
						
						
						$fun->msg("修改密码成功,正在跳转到登录页面...",$list_url['login'],3,$title="修改密码提示",$back_color="f78a12");
						$db->close();
					}
					else
					{
						$fun->msg("修改密码失败,请您重新修改密码",$list_url['change_password'],2,$title="修改密码提示",$back_color="f78a12");
					}
				}else{
					$fun->msg("您的用户名出现异常,我们已经对您的用户名做出冻结处理,您无法修改密码",$list_url['change_password'],3,$title="修改密码提示",$back_color="f78a12");
				}
					
			}else{
				$fun->msg("账号或者密码错误",$list_url['change_password'],2,$title="修改密码提示",$back_color="f78a12");
				$db->close();
			}
		}
	}
}
?>